package com.ucode.model.hrm.convert;

import cn.hutool.core.collection.CollUtil;
import com.ucode.model.hrm.HrmEmployeeCostDetail;
import com.ucode.model.hrm.HrmPaySlip;
import com.ucode.model.hrm.vo.HrmPaySlipVO;
import com.ucode.tool.base.Paginator;
import com.ucode.tool.util.JsonUtils;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Mapper
public interface HrmPaySlipConvert {

    HrmPaySlipConvert INSTANCE = Mappers.getMapper(HrmPaySlipConvert.class);

    Paginator<HrmPaySlipVO> convertPage(Paginator<HrmPaySlip> page);

    HrmPaySlipVO convert(HrmPaySlip bean);

    default HrmPaySlip convert(HrmEmployeeCostDetail bean, List<String> showColumns) {
        showColumns = CollUtil.isEmpty(showColumns) ? new ArrayList<>() : showColumns;
        HrmPaySlip hrmPaySlip = new HrmPaySlip();
        hrmPaySlip.setCompanyId(bean.getCompanyId());
        hrmPaySlip.setProjectId(bean.getProjectId());
        hrmPaySlip.setEmployeeId(bean.getEmployeeId());
        hrmPaySlip.setEmployeeName(bean.getEmployeeName());
        hrmPaySlip.setIdCard(bean.getIdCard());
        hrmPaySlip.setFeeMonth(bean.getFeeMonth());
        hrmPaySlip.setTotalPayable(bean.getTotalPayable());
        hrmPaySlip.setNetSalary(bean.getNetSalary());

        Map<String,String> detailInfo = new LinkedHashMap<>();
        if(showColumns.contains("baseSalary")){
            detailInfo.put("基本工资", bean.getBaseSalary().toString());
        }
        if(showColumns.contains("positionSalary")){
            detailInfo.put("岗位工资", bean.getPositionSalary().toString());
        }
        if(showColumns.contains("regionalDifference")){
            detailInfo.put("地区差异津贴", bean.getRegionalDifference().toString());
        }
        if(showColumns.contains("trafficSubsidy")){
            detailInfo.put("交通补贴", bean.getTrafficSubsidy().toString());
        }
        if(showColumns.contains("communicationSubsidy")){
            detailInfo.put("通讯补贴", bean.getCommunicationSubsidy().toString());
        }
        if(showColumns.contains("overtimeSalary")){
            detailInfo.put("加班工资", bean.getOvertimeSalary().toString());
        }
        if(showColumns.contains("professionalAllowance")){
            detailInfo.put("专业技术津贴", bean.getProfessionalAllowance().toString());
        }
        if(showColumns.contains("comprehensiveSubsidy")){
            detailInfo.put("综合补贴", bean.getComprehensiveSubsidy().toString());
        }

        if(showColumns.contains("individualPension")){
            detailInfo.put("养老", bean.getIndividualPension().toString());
        }
        if(showColumns.contains("individualUnemployment")){
            detailInfo.put("失业", bean.getIndividualUnemployment().toString());
        }
        if(showColumns.contains("individualMedical")){
            detailInfo.put("医疗", bean.getIndividualMedical().toString());
        }
        if(showColumns.contains("individualLargeMedical")){
            detailInfo.put("大病医疗", bean.getIndividualLargeMedical().toString());
        }
        if(showColumns.contains("longTermPassportInsurance")){
            detailInfo.put("长期护照险", bean.getLongTermPassportInsurance().toString());
        }
        if(showColumns.contains("individualSocialSubtotal")){
            detailInfo.put("社保小计", bean.getIndividualSocialSubtotal().toString());
        }
        if(showColumns.contains("individualHousingFund")){
            detailInfo.put("公积金", bean.getIndividualHousingFund().toString());
        }

        if(showColumns.contains("salaryReissue")){
            detailInfo.put("工资补发", bean.getSalaryReissue().toString());
        }
        if(showColumns.contains("reimbursement")){
            detailInfo.put("报销金额", bean.getReimbursement().toString());
        }
        if(showColumns.contains("commission")){
            detailInfo.put("提成金额", bean.getCommission().toString());
        }
        if(showColumns.contains("socialSecurityDeduction")){
            detailInfo.put("社保扣除", bean.getSocialSecurityDeduction().toString());
        }
        if(showColumns.contains("housingFundDeduction")){
            detailInfo.put("公积金扣除", bean.getHousingFundDeduction().toString());
        }
        if(showColumns.contains("individualIncomeTax")){
            detailInfo.put("个人所得税", bean.getIndividualIncomeTax().toString());
        }
        hrmPaySlip.setDetailInfo(JsonUtils.toJsonString(detailInfo));
        hrmPaySlip.setVisible(false);
        hrmPaySlip.setCostId(bean.getId());
        hrmPaySlip.setBatchnum(bean.getBatchnum());
        return hrmPaySlip;
    }
}
